import { defineStore } from 'pinia'
import { requestBannerList, requestSearchBannerByNameOrTime, requestUpadtaBannerById, requestDeleteBannerById } from './manage-banner.api'

export default defineStore('manageBanner', {
    state: () => {
        return {
        }
    },
    getters: {
    },
    actions: {
        // 获取轮播图数据
        getBannerList() {
            return new Promise((resolve, reject) => {
                requestBannerList().then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 通过名称/时间查找轮播图
        getBannerByNameOrTime(data: Object) {
            return new Promise((resolve, reject) => {
                requestSearchBannerByNameOrTime(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 通过id更新轮播图
        getUpadtaBannerById(data: Object) {
            return new Promise((resolve, reject) => {
                requestUpadtaBannerById(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据id删除轮播图
        getDeleteBannerById(data: Object) {
            return new Promise((resolve, reject) => {
                requestDeleteBannerById(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },
    }
})
